(()=>{
	window.Data = class {
		constructor() {
			this._data = {};
			this._modifyData = {};
		}
		
		/**
		 * 获取模型中的数据
		 * @param key
		 * @param defaultValue
		 * @returns {*}
		 */
		get(key, defaultValue) {
			if(typeof key == 'undefined') {
				return JSON.parse(JSON.stringify(this._data));
			}
			
			let value = this._data[key];
			defaultValue = typeof defaultValue == 'undefined' ? null : defaultValue;
			
			if(!value) {
				return defaultValue;
			}
			
			return value;
		}
		
		/**
		 * 设置模型中的数据
		 * @param key
		 * @param value
		 * @returns {Window.Model}
		 */
		set(key, value) {
			if(Core.isObject(key)) {
				this._data = key;
				this._modifyData = key;
			} else {
				this._data[key] = value;
				this._modifyData[key] = value;
			}
			
			return this;
		}
		
		__getValueByFunctionName(name, defaultValue) {
			let methodInfo = this.constructor.__parseValueNameFromFunctionName(name);
			
			switch(methodInfo.method.toLowerCase()) {
				case 'get':
					return this.get(methodInfo.value, defaultValue);
			}
			
			return this;
		}
		
		__setValueByFunctionName(name, value) {
			let methodInfo = this.constructor.__parseValueNameFromFunctionName(name);

			switch(methodInfo.method.toLowerCase()) {
				case 'set':
					return this.set(methodInfo.value, value);
			}

			return this;
		}
		
		static __parseValueNameFromFunctionName(name) {
			name = name.replace(/^\s+/, '').replace(/\s+$/, '');
			let operator = name.substr(0, 3).toLocaleLowerCase();
			let valueName = name.substr(3);
			valueName = valueName.substr(0,1).toLowerCase() + valueName.substr(1);
			valueName = valueName.replace(/([A-Z])/, '_$1');

			return {method:operator, value:valueName};
		}
	};
	
	Core.setToParentWindow('Data', Data);
})();